#_*_ coding:UTF-8 _*_
__author__ = 'shaowei'

import sys
import os
import HandleXcodeBuild


def check_input_bool(default_path):
	"""from command line check user input:yes or no"""
	prompt_input = "是否开始编译默认项目-  " + default_path + " ; yes or no :"
	while True:
		user_input = raw_input(prompt_input)
		user_input = user_input.lower()
		if user_input == "yes":
			return True
		elif user_input == "no":
			return False
		else:
			print "only input 'yes' or 'no', please input again "


def get_project_path(default_work_path):
	"""prompt user input project root path,if no or error input, use 'default_work_path' """
	work_path = raw_input("please input project root folder path:\n")
	if os.path.isdir(os.path.expanduser(work_path)):
		print "start build:", work_path
	else:
		print "路径：", work_path, "不存在"
		user_select = check_input_bool(default_work_path)
		if user_select:
			work_path = default_work_path
		else:
			print "程序结束，退出。"
			sys.exit()  # 退出程序

	return work_path


def get_build_configuration():
	"""prompt user input build configuration 1."""
	configuration_list = HandleXcodeBuild.get_configuration_list()
	if len(configuration_list) is 0:
		print "build configuration no exist, please check current folder have xcode-project"
		sys.exit()

	print "project build configuration list:"
	index = 0
	for item in configuration_list:
		print "%s.%s" % (index, item)
		index += 1

	list_length = len(configuration_list)
	user_select = 0
	while 1:
		user_select = int(raw_input("please input build option index 0 ~ %s :" % (list_length-1)))
		if user_select < 0 or user_select >= list_length:
			print "your input index '%s' no exist." % user_select
		else:
			break

	return configuration_list[user_select]











